package us.gaaoc.framework.webapp.backingbeans.admin;

import java.util.List;
import java.util.Map;

import javax.faces.component.UIParameter;
import javax.faces.component.UISelectItem;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;

import org.apache.log4j.Logger;

import us.gaaoc.framework.businessmodel.Filing;
import us.gaaoc.framework.dao.ModelFacade;
import us.gaaoc.framework.dao.ModelFacadeHibernate;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;
import us.gaaoc.framework.webapp.backingbeans.caseTypes.StatusType;
import us.gaaoc.framework.webapp.backingbeans.profile.Links;

/**
 * 
 * @author hea
 * @date Apr 21, 2006
 * @version: GAJE 1.5
 *
 */
public class CivilCaseType extends BaseBackingBean {

	/**
	 * Properties
	 */
	private Logger LOG = Logger.getLogger(CivilCaseType.class);

	private UIParameter uuidClicked;

	private UIParameter clickedClear;
	 
	private UISelectOne statusUI;

	private StatusType status;	
 
	private Filing filing; 	
	 
	private DataModel civilFilingDataTable ;

	private String courtUuid;
	
	/**
	 * Constructor
	 *
	 */
	public CivilCaseType() {
		this.statusUI = new UISelectOne();
		this.status = new StatusType();
		for (Links links : this.status.getMenu()) {
			SelectItem item = new SelectItem(links.getNavigationRule(), links
					.getText());
			UISelectItem uiItem = new UISelectItem();
			uiItem.setValue(item);
			this.statusUI.getChildren().add(uiItem);
		}
		
		courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		
		//	type = civil (2)
		List caseRecordList = this.getModelFacade().findCaseFilingsByType(2, courtUuid);  
		civilFilingDataTable =new ListDataModel();
		civilFilingDataTable.setWrappedData(caseRecordList); 
	}

	/**
	 * Getter for property civilFilingDataTable
	 * @return civilFilingDataTable
	 */
	public DataModel getCivilFilingDataTable() {
		return civilFilingDataTable;
	}

	/**
	 * Setter for property civilFilingDaaTable
	 * @param civilFilingDataTable
	 */
	public void setCivilFilingDataTable(DataModel civilFilingDataTable) {
		this.civilFilingDataTable = civilFilingDataTable;
	}
 
	/**
	 * Getter for property clickedClear
	 * @return clickedClear
	 */
	public UIParameter getClickedClear() {
		return clickedClear;
	}

	/**
	 * Setter for property clickedClear
	 * @param clickedClear
	 */
	public void setClickedClear(UIParameter clickedClear) {
		this.clickedClear = clickedClear;
	}
	
	/**
	 * Getter for property statusUI
	 * @return statusUI
	 */
	public UISelectOne getStatusUI() {
		return statusUI;
	}

	/**
	 * Setter for property statusUI
	 * @param statusUI
	 */
	public void setStatusUI(UISelectOne statusUI) {
		this.statusUI = statusUI;
	}

	/**
	 * Getter for property uuidClicked
	 * @return uuidClicked
	 */
	public UIParameter getUuidClicked() {
		return uuidClicked;
	}

	/**
	 * Setter for property uuidClicked
	 * @param uuidClicked
	 */
	public void setUuidClicked(UIParameter uuidClicked) {
		this.uuidClicked = uuidClicked;
	}

	/**
	 * Getter for property filing
	 * @return filing
	 */
	public Filing getFiling() {
		return filing;
	}

	/**
	 * Setter for property filing
	 * @param filing
	 */
	public void setFiling(Filing filing) {
		this.filing = filing;
	}
 
	/**
	 * This method navigates user to the case details page 
	 * @return String
	 */
	@SuppressWarnings("unchecked")
	public String gotoCaseDetailPage() {
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	sessionMap.put("caseUuid", caseUuid);
	 	sessionMap.put("from", "CivilCaseTypePage");
	 	return "caseDetailsPage";
	
	}
	
/*	
	public String submitStatus() {
		String navigationString = "";
		if (this.getStatusUI().getValue().equals("received"))
			navigationString = "received";
		else if (this.getStatusUI().getValue().equals("imported"))
			navigationString = "imported";
		else if (this.getStatusUI().getValue().equals("rejected"))
			navigationString = "rejected";
		else if (this.getStatusUI().getValue().equals("served"))
			navigationString = "served";
		else if (this.getStatusUI().getValue().equals("non-served"))
			navigationString = "non-served";
		else if (this.getStatusUI().getValue().equals("disposed"))
			navigationString = "disposed";
		else if (this.getStatusUI().getValue().equals("negotiate"))
			navigationString = "negotiate";
		return navigationString;
	}
*/
	
	/**
	 * This method navigates user to the previous page
	 * @return String
	 */
	public String back(){
		return "back";
	}
	
	/**
	 * This method clears the case record from this page and puts in the
	 * trash can
	 * @return String
	 */
	public String clearRecord() {
		this.filing = (Filing) this.getClickedClear().getValue();
		this.getModelFacade().updateCaseRecordForClearCase(
				this.getFiling().getUuid(), true, courtUuid);	 	
		return "stay";
	}
}